package com.temp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.temp.dto.SearchChatDTO;
import com.temp.entity.ChatMessage;
import com.temp.entity.ChatUser;
import com.temp.mapper.ChatMessageMapper;
import com.temp.service.ChatMessageService;
import com.temp.vo.CustomPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Service
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage> implements ChatMessageService {

    @Autowired
    private ChatMessageMapper chatMessageMapper;

    @Override
    public CustomPageVO<ChatUser> findALlUserChat(SearchChatDTO chatDTO) {
        CustomPageVO<ChatUser> customPageVO = new CustomPageVO<>();
        Integer count = Optional.ofNullable(chatMessageMapper.countAllUserChat(chatDTO)).orElse(0);
        customPageVO.setTotal(count);
        if(count < 1) {
            customPageVO.setDataList(Collections.emptyList());
            return customPageVO;
        }

        List<ChatUser> permissions = chatMessageMapper.findALlUserChats(chatDTO);
        customPageVO.setDataList(permissions);
        return customPageVO;
    }
}
